/*
 * Copyright 2023, Haiku, Inc. All rights reserved.
 * Distributed under the terms of the MIT License.
 */

#include "accelerant.h"

#include <stdlib.h>
#include <string.h>

// 加速器钩子函数

extern "C"
{

    // 通用
    status_t ACCELERANT_CLONE_INFO_SIZE(void);
    status_t GET_ACCELERANT_CLONE_INFO(void *data);
    status_t CLONE_ACCELERANT(void *data);
    void UNINIT_ACCELERANT(void);
    status_t GET_ACCELERANT_DEVICE_INFO(accelerant_device_info *info);
    sem_id ACCELERANT_RETRACE_SEMAPHORE(void);

    // 模式配置
    uint32 ACCELERANT_MODE_COUNT(void);
    status_t GET_MODE_LIST(display_mode *mode_list);
    status_t PROPOSE_DISPLAY_MODE(display_mode *target, const display_mode *low, const display_mode *high);
    status_t SET_DISPLAY_MODE(display_mode *mode);
    status_t GET_DISPLAY_MODE(display_mode *current_mode);
    status_t GET_FRAME_BUFFER_CONFIG(frame_buffer_config *config);
    status_t GET_PIXEL_CLOCK_LIMITS(display_mode *mode, uint32 *low, uint32 *high);
    status_t GET_EDID_INFO(void *info, size_t size, uint32 *_version);

    // 光标
    status_t SET_CURSOR_SHAPE(uint16 width, uint16 height, uint16 hot_x, uint16 hot_y, uint8 *andMask, uint8 *xorMask);
    void MOVE_CURSOR(uint16 x, uint16 y);
    void SHOW_CURSOR(bool is_visible);

} // extern "C"

// 通用
status_t
ACCELERANT_CLONE_INFO_SIZE(void)
{
    return ls7a2000_accelerant_clone_info_size();
}

status_t
GET_ACCELERANT_CLONE_INFO(void *data)
{
    return ls7a2000_get_accelerant_clone_info(data);
}

status_t
CLONE_ACCELERANT(void *data)
{
    return ls7a2000_clone_accelerant(data);
}

void UNINIT_ACCELERANT(void)
{
    ls7a2000_uninit_accelerant();
}

status_t
GET_ACCELERANT_DEVICE_INFO(accelerant_device_info *info)
{
    return ls7a2000_get_accelerant_device_info(info);
}

sem_id
ACCELERANT_RETRACE_SEMAPHORE(void)
{
    return ls7a2000_accelerant_retrace_semaphore();
}

// 模式配置
uint32
ACCELERANT_MODE_COUNT(void)
{
    return ls7a2000_accelerant_mode_count();
}

status_t
GET_MODE_LIST(display_mode *mode_list)
{
    return ls7a2000_get_mode_list(mode_list);
}

status_t
PROPOSE_DISPLAY_MODE(display_mode *target, const display_mode *low, const display_mode *high)
{
    // 目前不支持模式建议，直接返回成功
    return B_OK;
}

status_t
SET_DISPLAY_MODE(display_mode *mode)
{
    return ls7a2000_set_display_mode(mode);
}

status_t
GET_DISPLAY_MODE(display_mode *current_mode)
{
    return ls7a2000_get_display_mode(current_mode);
}

status_t
GET_FRAME_BUFFER_CONFIG(frame_buffer_config *config)
{
    return ls7a2000_get_frame_buffer_config(config);
}

status_t
GET_PIXEL_CLOCK_LIMITS(display_mode *mode, uint32 *low, uint32 *high)
{
    return ls7a2000_get_pixel_clock_limits(mode, low, high);
}

status_t
GET_EDID_INFO(void *info, size_t size, uint32 *_version)
{
    return ls7a2000_get_edid_info(info, size, _version);
}

// 光标
status_t
SET_CURSOR_SHAPE(uint16 width, uint16 height, uint16 hot_x, uint16 hot_y, uint8 *andMask, uint8 *xorMask)
{
    return ls7a2000_set_cursor_shape(width, height, hot_x, hot_y, andMask, xorMask);
}

void MOVE_CURSOR(uint16 x, uint16 y)
{
    ls7a2000_move_cursor(x, y);
}

void SHOW_CURSOR(bool is_visible)
{
    ls7a2000_show_cursor(is_visible);
}